using Cobra11Undercover.Material;
using Engine.Graphics;
using Engine.Graphics.Shaders;
using SharpDX.Direct3D11;
using System;

namespace Cobra11Undercover.Shaders.C11UndercoverShaders
{
    internal class Material000 : ShaderBaseC11Undercover, ISetShaderValues, ISetBlendStates, ISetSamplerStates
    {
        #region Private Fields

        private BlendState blendstate;
        private int lastBumpTextureID1 = -1;
        private int lastBumpTextureID2 = -1;
        private int lastBumpTextureID3 = -1;
        private uint lastHashcodeMappingMatrix1 = 0;
        private uint lastHashcodeMappingMatrix2 = 0;
        private uint lastHashcodeMappingMatrix3 = 0;
        private int lastTextureID1 = -1;
        private int lastTextureID2 = -1;
        private int lastTextureID3 = -1;
        private string name;

        #endregion Private Fields

        #region Public Constructors

        public Material000(Device renderDevice, string shaderDirectory, ShaderManager shaderManager)
            : base(renderDevice, shaderManager)
        {
            base.SetSamplerStateObject(this);
            base.SetBlendStateObject(this);
            this.name = shaderDirectory;

            this.name = shaderDirectory;
            base.LoadShader(renderDevice, shaderDirectory + "\\material00.fx", "ps_main", "vs_main");
            base.inputLayout = new InputLayout(renderDevice, base.shaderByteCodeVS, VertexStructures.C11UCVertexElements.elements);
            base.inputLayout.DebugName = "Input Layout Material00";
        }

        #endregion Public Constructors

        #region Public Properties

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion Public Properties

        #region Public Methods

        public new void Dispose()
        {
            base.Dispose();
        }

        public new void SetBlendStates()
        {
            base.shaderManager.SetBlendState(StandardBlendStates.NoAlpha);
        }

        public new void SetProperties(int materialID, MaterialManager materialManager)
        {
            //this.device.ImmediateContext.OutputMerger.SetBlendState(this.blendstate, sampleMask: 255);

            C11Material material = (C11Material)materialManager.GetMaterialForGame(materialID);

            short TextureID1 = material.GetTextureIDTexture1(materialManager);
            short TextureID2 = material.GetTextureIDTexture2(materialManager);
            short TextureID3 = material.GetTextureIDTexture3(materialManager);
            short BumpTextureID1 = material.GetTextureIDBumbTexture1(materialManager);
            short BumpTextureID2 = material.GetTextureIDBumbTexture2(materialManager);
            short BumpTextureID3 = material.GetTextureIDBumbTexture3(materialManager);

            base.SetTextureUvMatrix(material);

            ShaderBase.SetTexture(0, materialManager.Textures[TextureID1], base.Device);
            ShaderBase.SetTexture(2, materialManager.Textures[TextureID2], base.Device);
            ShaderBase.SetTexture(4, materialManager.Textures[TextureID3], base.Device);
        }

        public void SetSamplerStates()
        {
            base.SetSamplerState(SamplerStateCollection.Standard, 0);
            base.SetSamplerState(SamplerStateCollection.Standard, 2);
            base.SetSamplerState(SamplerStateCollection.Standard, 4);
        }

        #endregion Public Methods
    }
}